package cn.itrip.service.impl;

import cn.itrip.entity.ItripHotelFeature;
import cn.itrip.dao.ItripHotelFeatureDao;
import cn.itrip.service.ItripHotelFeatureService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (ItripHotelFeature)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:34:56
 */
@Service("itripHotelFeatureService")
public class ItripHotelFeatureServiceImpl implements ItripHotelFeatureService {
	@Resource
	private ItripHotelFeatureDao itripHotelFeatureDao;

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripHotelFeature queryById(Long id) {
		return this.itripHotelFeatureDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripHotelFeature 筛选条件
	 * @param pageRequest       分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripHotelFeature> queryByPage(ItripHotelFeature itripHotelFeature, PageRequest pageRequest) {
		long total = this.itripHotelFeatureDao.count(itripHotelFeature);
		return new PageImpl<>(this.itripHotelFeatureDao.queryAllByLimit(itripHotelFeature, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripHotelFeature 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripHotelFeature insert(ItripHotelFeature itripHotelFeature) {
		this.itripHotelFeatureDao.insert(itripHotelFeature);
		return itripHotelFeature;
	}

	/**
	 * 修改数据
	 *
	 * @param itripHotelFeature 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripHotelFeature update(ItripHotelFeature itripHotelFeature) {
		this.itripHotelFeatureDao.update(itripHotelFeature);
		return this.queryById(itripHotelFeature.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripHotelFeatureDao.deleteById(id) > 0;
	}
}
